package com.example.administrator.base.fragment;


import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.base.activity.AddPoint;
import com.example.administrator.base.activity.ChangeCityBlue;
import com.example.administrator.base.activity.HowToUse;
import com.example.administrator.base.activity.Ring;
import com.example.administrator.base.activity.ScanActivity;
import com.example.administrator.base.activity.SerchCar;
import com.example.administrator.base.activity.test;
import com.example.administrator.base.adapt.AdapterRecyclerViewMain;
import com.example.administrator.base.bean.ModelMainItem;
import com.example.administrator.base.R;
import com.example.administrator.base.util.RxRecyclerViewDivider;
import com.example.administrator.base.util.SharedPreferencesUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class SetFragment extends Fragment {
    @InjectView(R.id.recyclerview)
    RecyclerView recyclerview;
    private List<ModelMainItem> mData;
    private int mColumnCount = 3;




    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_set, container, false);
        ButterKnife.inject(this, view);
        initView();
        initData();
        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }
    private void initData() {


    }


    private void initView() {
        String admintype= String.valueOf(SharedPreferencesUtils.getParam(getActivity(),"administratorType",""));
        if (mColumnCount <= 1) {
            LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
            layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
            recyclerview.setLayoutManager(layoutManager);
        } else {
            GridLayoutManager gridLayoutManagerManager = new GridLayoutManager(getActivity(), mColumnCount);
            recyclerview.setLayoutManager(gridLayoutManagerManager);
        }

        recyclerview.addItemDecoration(new RxRecyclerViewDivider(dp2px(getActivity(), 5f)));
        mData = new ArrayList<>();
        mData.add(new ModelMainItem("GPRS开车锁", R.drawable.open_lock, ScanActivity.class, "openlock"));
        mData.add(new ModelMainItem("蓝牙开车锁", R.drawable.bule_open_lock, ScanActivity.class, "openlockb"));
        mData.add(new ModelMainItem("GPRS查看车锁详情", R.drawable.lock_message_gprs, ScanActivity.class, "lockmessageG"));
        mData.add(new ModelMainItem("蓝牙查看车锁详情", R.drawable.lock_message, ScanActivity.class, "lockmessage"));
        mData.add(new ModelMainItem("车锁响铃", R.drawable.ring, Ring.class, "Ring"));
        mData.add(new ModelMainItem("车辆绑定城市", R.drawable.lock_city, ScanActivity.class, "bandcar"));
        if (admintype.equals("5")){
            mData.add(new ModelMainItem("车辆解绑城市", R.drawable.unlock_city, ScanActivity.class, "unbandcar"));
            mData.add(new ModelMainItem("蓝牙解绑城市", R.drawable.changelockblue, ChangeCityBlue.class, "unbandcarblue"));
            mData.add(new ModelMainItem("换锁登记", R.drawable.lock_lock_city, ScanActivity.class, "bandlock"));
        }
        mData.add(new ModelMainItem("故障车登记", R.drawable.broken_bike, ScanActivity.class, "brokencar"));
        mData.add(new ModelMainItem("维修中车辆登记", R.drawable.fix_car, ScanActivity.class, "fixcar"));
        mData.add(new ModelMainItem("维修中置回", R.drawable.circle_seek, ScanActivity.class, "brokenback"));
        mData.add(new ModelMainItem("查找车辆", R.drawable.serch_car, ScanActivity.class, "serchcar"));
        mData.add(new ModelMainItem("最近用车人员", R.drawable.search_people, ScanActivity.class, "serchpeople"));
        mData.add(new ModelMainItem("辖区车辆总览", R.drawable.allbicycle, SerchCar.class, "serchallcar"));
       // mData.add(new ModelMainItem("查看热力图", R.drawable.heatmap, SerchCar.class, "hotmap"));
        mData.add(new ModelMainItem("添加停放点", R.drawable.bullet, AddPoint.class, "1"));
        mData.add(new ModelMainItem("使用说明", R.drawable.how_to_user, HowToUse.class, "1"));
       /* mData.add(new ModelMainItem("定位维修点", R.drawable.location_fix, test.class, "1"));
        mData.add(new ModelMainItem("发起新的工单", R.drawable.new_order, test.class, "adddispatchlist"));*/



        AdapterRecyclerViewMain recyclerViewMain = new AdapterRecyclerViewMain(mData);
        recyclerview.setAdapter(recyclerViewMain);
    }

    public  int dp2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }
}
